package com.weitu.permission.log.service.impl;

import com.weitu.permission.log.entity.HandleLog;
import com.weitu.permission.log.entity.LoginLog;
import com.weitu.permission.log.mapper.LogMapper;
import com.weitu.permission.log.service.LogService;
import com.weitu.util.DateTimeUtil;
import com.weitu.util.IDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017/3/18
 */
@Service
public class LogServiceImpl implements LogService {

    private final LogMapper logMapper;

    @Autowired
    public LogServiceImpl(LogMapper logMapper) {
        this.logMapper = logMapper;
    }

    @Override
    public Integer insertHandleLog(HandleLog handleLog) {
        String dateTime= DateTimeUtil.formatterDateTime();
        String uuid= IDGenerator.getId();
        handleLog.setId(uuid);
        handleLog.setHandleTime(dateTime);
        return logMapper.insertHandleLog(handleLog);
    }

    @Override
    public Integer insertLoginLog(LoginLog loginLog) {
        String dateTime= DateTimeUtil.formatterDateTime();
        String uuid= IDGenerator.getId();
        loginLog.setId(uuid);
        loginLog.setLoginTime(dateTime);
        return logMapper.insertLoginLog(loginLog);
    }

    @Override
    public Integer updateLoginLogById(LoginLog loginLog) {
        String dateTime= DateTimeUtil.formatterDateTime();
        loginLog.setOfflineTime(dateTime);
        return logMapper.updateLoginLogById(loginLog);
    }

    @Override
    public List<HandleLog> queryHandleLogList(Map<String, Object> map) {
        return this.logMapper.queryHandleLogList(map);
    }

    @Override
    public List<LoginLog> queryLoginLogList(Map<String, Object> map) {
        return this.logMapper.queryLoginLogList(map);
    }

    @Override
    public int queryHandleLogCount(Map<String, Object> map) {
        return this.logMapper.queryHandleLogCount(map);
    }

    @Override
    public int queryLoginLogCount(Map<String, Object> map) {
        return this.logMapper.queryLoginLogCount(map);
    }
}
